from flask import Flask, jsonify
from hash_app.hahsh import HASH
from hash_app.db import SQLITE
from hash_app.func import FUNC

app = Flask(__name__)
obj_db = SQLITE()
obj_func = FUNC()


@app.route('/')
def hello_world():
    hash = HASH()
    dit_num = hash.get_num_percent_in_recent_100('over', 52)
    arr_list = obj_db.get_hash_list()
    print(arr_list)

    return "hello world"


@app.route('/hash', methods=['GET'])
def hash():
    hash = HASH()
    dit_num = hash.get_num_percent_in_recent_100('over', 52)
    return dit_num




@app.route('/history', methods=['GET'])
def history():
    arr_list = obj_db.get_hash_list()
    arr_100 = arr_list[-100:]
    arr_100_num = list(map(lambda x: x["hash"], arr_100))
    dit_ret = {
        'state': 1,
        'data': arr_list,
        '100': obj_func.get_percent(arr_100_num)
    }
    return jsonify(dit_ret)


if __name__ == '__main__':
    app.run()
